package com.feeyo.groundservice.ws.utils

import java.security.SecureRandom
import java.security.cert.CertificateException
import java.security.cert.X509Certificate
import javax.net.ssl.SSLContext
import javax.net.ssl.TrustManager
import javax.net.ssl.X509TrustManager

/**
 *作者：QLH on 2024-04-30
 *描述：忽略SSL验证
 */
object SSLSocketClient {


    fun getSSLSocketFactory() = SSLContext.getInstance("SSL").apply {
        init(null, getTrustAllManager(), SecureRandom())
    }.socketFactory

    fun getTrustAllCert() = getTrustAllManager()[0] as X509TrustManager


    private fun getTrustAllManager() = arrayOf<TrustManager>(object : X509TrustManager {
        override fun getAcceptedIssuers(): Array<X509Certificate> {
            return arrayOf()
        }

        @Throws(CertificateException::class)
        override fun checkClientTrusted(chain: Array<X509Certificate>, authType: String) {}

        @Throws(CertificateException::class)
        override fun checkServerTrusted(chain: Array<X509Certificate>, authType: String) {}
    })

}